package com.eblacorp.archive.util.scanning;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class ArchiveEntityRepository {
	
	private Map<String,Class<?>> classRepository;
	private Map<String, Map<String, Field>> propertyRepository;
	
	public ArchiveEntityRepository(){
		classRepository = new HashMap<String, Class<?>>();
		propertyRepository = new HashMap<String, Map<String,Field>>();
	}
	
	
	public void addEntity(String symbolicName, Class<?> clazz){
		classRepository.put(symbolicName, clazz);
	}
	
	public void addProperty(String classSymbolicName, String propertySymbolicName, Field field){
		Map<String,Field> properties = propertyRepository.get(classSymbolicName);
		if(properties == null){
			properties = new HashMap<String,Field>();
		}
		properties.put(propertySymbolicName, field);
		propertyRepository.put(classSymbolicName, properties);
	}
	
	public Class<?> getEntity(String symbolicName ){
		return classRepository.get(symbolicName);
	}
	
	public Field getProperty(String classSymbolicName, String propertySymbolicName){
		Map<String,Field> properties = propertyRepository.get(classSymbolicName);
		if (properties == null || properties.isEmpty()){
			return null;
		}
		return properties.get(propertySymbolicName);
	}
	
	public Map<String, Class<?>> getClassRepository() {
		return classRepository;
	}
	public void setClassRepository(Map<String, Class<?>> classRepository) {
		this.classRepository = classRepository;
	}
	public Map<String, Map<String, Field>> getPropertyRepository() {
		return propertyRepository;
	}
	public void setPropertyRepository(
			Map<String, Map<String, Field>> propertyRepository) {
		this.propertyRepository = propertyRepository;
	}
}
